package com.qfedu.stussm.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qfedu.stussm.dao.NewsDao;
import com.qfedu.stussm.entity.Email;
import com.qfedu.stussm.entity.News;
import com.qfedu.stussm.service.intf.NewsService;
import com.qfedu.stussm.vo.PageBeanVo;
import com.qfedu.stussm.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class NewsServiceImpl implements NewsService {
    @Autowired
    private NewsDao newsDao;
    @Override
    public int add(News news) {
        return newsDao.add(news);
    }

    @Override
    public PageBeanVo selectAll(int page, int limit) {
        PageHelper.startPage(page, limit);
        PageInfo<News> newsPageInfo = new PageInfo<>(newsDao.selectAll());
        return new PageBeanVo(newsPageInfo.getTotal(), newsPageInfo.getList());
    }

    @Override
    public R update(News news) {
        if (newsDao.update(news) > 0) {
            return R.ok();
        } else {
            return R.fail();
        }
    }

    @Override
    public R del(int id) {
        if (newsDao.del(id) > 0) {
            return R.ok();
        } else {
            return R.fail();
        }
    }
}
